<template>
    <div class="login_container">
    <div class="login_box">
        <div class="avatar_box">
            <img src="../assets/logo.png" alt="">
        </div>
        <el-form ref="loginFormRef" :model="loginForm" :rules="rules" label-width="0px" class="logon_form">
            <el-form-item prop="name">
                <el-input v-model="loginForm.name" prefix-icon="iconfont icon-yonghu"></el-input>
            </el-form-item>
             <el-form-item prop="password">
                <el-input type="password" v-model="loginForm.password" prefix-icon="iconfont icon-mima"></el-input>
            </el-form-item>
             <el-form-item>
               <el-button type="primary" @click="login">登录</el-button>
               <el-button type="info" @click="resetLoginForm">重置</el-button>
            </el-form-item>
        </el-form>    
    </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            loginForm :{
                name:'',
                password:''
            },
            rules: {
                //验证用户名
                name: [
                    { required: true, message:'请输入用户名', trigger: 'blur' }
                ],
                //验证密码
                password: [
                    { required: true, message:'请输入用密码',  trigger: 'blur' },
                    { min: 3, max: 10, trigger: 'blur' }
                ]
             }
        }
    },
    methods : {
        //重置登录表单
        resetLoginForm(){
            this.$refs.loginFormRef.resetFields();
        },
        //登录
        login() {
            this.$refs.loginFormRef.validate( val => {
                if (!val) return;
                // const result = await this.$http.post('login',this.loginForm);
                if(this.loginForm.name != 'admin' || this.loginForm.password != '123456'){
                    return this.$message.error('登录失败')
                } ;
                this.$message.success('登录成功')
                window.sessionStorage.setItem('token','shulijin')
                this.$router.push('/home')
            })
        }
    }

}
</script>
<style lang="less" scoped>
.login_container {
    background:#2b4b6b;
    height:100%;
}
.login_box {
    width:450px;
    height:300px;
    background-color:#fff;
    border-radius: 3px;
    position:absolute;
    left:50%;
    top:50%;
    transform: translate(-50%,-50%);
    .avatar_box {
        width:130px;
        height:130px;
        border:3px solid #eee;
        border-radius: 50%;
        padding:10px;
        position: absolute;
        left:50%;
        background-color:#fff;
        transform: translate(-50%,-50%);
        img {
            width:100%;
            height:100%;
            border-radius: 50%;
            background-color:#eee;
        }
    }
    .logon_form {
        width:100%;
        position:absolute;
        padding:0 20px;
        box-sizing: border-box;
        bottom:0;
    }
    .el-form-item {
        text-align: center;
    }
}
</style>